package cn.crc.web.stream;

import cn.crc.web.tool.TestUserVo;

import java.util.*;
import java.util.stream.Collectors;

/**
 * Java流处理_25.4.16_liuhz
 */
public class TestStream1 {
    public static void main(String[] args) {
        TestStream1.test2过滤并大写();
        TestStream1.test2动态修改对象();
    }

    private static void test2过滤并大写(){
        List<String> list = Arrays.asList("apple", "banana", "cherry", "date", "elderberry");
        List<String> result = list.stream()
                .filter(s-> s.startsWith("a"))
                .map(String::toUpperCase)
                .collect(Collectors.toList());//过滤出以"a’开头的字符串，并将其转换为大写
        System.out.println("过滤并大写：" + result);
    }
    
    private static void test2动态修改对象(){
        List<String> list1 = listData.stream().filter(x -> x.getSalary() > 8000).map(TestUserVo::getUsername).collect(Collectors.toList());
        System.out.println("高于8000薪资到人员信息  ==>  " + list1);
        Optional<TestUserVo> max = listData.stream().max(Comparator.comparingInt(TestUserVo::getSalary));
        System.out.println("最高薪资到人员信息  ==>  " + max.get());

        List<TestUserVo> list6 = listData.stream().map(person -> {
            person.setSalary(person.getSalary() + 1000);
            return person;
        }).collect(Collectors.toList());
        list6.forEach(System.out::println);
        //System.out.println("员工薪资全部增加1000  ==>  " + list6);
    }

    private static List<TestUserVo> listData = new ArrayList<TestUserVo>();
    static {
        listData.add(new TestUserVo("苹果", "13022334455","北京",8900));
        listData.add(new TestUserVo("菠萝", "13533445566","上海",7000));
        listData.add(new TestUserVo("香蕉", "18244556677","广州",7800));
        listData.add(new TestUserVo("榴莲", "18511223344","杭州",8200));
        listData.add(new TestUserVo("蓝莓", "15055667788","成都",9500));
        listData.add(new TestUserVo("西瓜", "15544556677","昆明",7900));
    }
}
